import { Injectable, NestMiddleware, Next, Req, Res } from "@nestjs/common"
import { NextFunction, Request, Response } from "express"

@Injectable()
export class LoginMiddleware implements NestMiddleware {
  use(@Req() req: Request, @Res() res: Response, @Next() next: NextFunction) {
    if (req.cookies["author-cookie"] === undefined) {
      res.json({
        status: "error",
        message: "登录过期，请重新登录！",
        code: "expire"
      })
    } else {
      next()
    }
  }
}
